package com.wc.算法提高课.E第五章_数学知识.欧拉函数.可见的点;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

/**
 * @Author congge
 * @Date 2024/10/4 18:00
 * @description https://www.acwing.com/problem/content/description/203/
 */
public class Main {
    /**
     * 背景：
     * 欧拉函数 phi[i] 表示从 1 ~ i 与 i 互质的个数
     * 公式：
     * x = /mul_1_n p[i] * c[i], p[i] 为质因子, c[i]为质因子的次幂<p>
     * phi[x] = x * /mul_1_n (1 - 1 / p[i])<p>
     * 如果i % primes[j] == 0<p>
     * 推导 phi[i * primes[j]] = phi[i] * primes[j]<p>
     * 反之<p>
     * phi[i * primes[j]]<p>
     * = primes[j] * (1 - 1 / primes[j]) * phi[i] <p>
     * = phi[i] * (primes[j] - 1)<p>
     * 思路：O(n)的时间复杂度
     * 查找可见的广, y = k x, 只有 (x[0], y[0]) 第一个点可见, 那么y = y[0] / x[0] * x
     * 差有多少个 k 可以直接计算出来, 那么就说明 y[0], x[0]一定是化为最简的分数, 也就是这两个数互质<p>
     * 那么y = x 的下半区 一列 x 中有多少个数与 x 互质呢也就是 phi[i], 行一次, 列一次, y = x 的一个点多了一个点 <p>
     * res = 1 + /sum_1_n phi[i] <p>
     * 思路2: O(n^2)
     * @see com.wc.算法基础课.D第四讲数学知识.欧拉函数.可见的点
     */
    static FastReader sc = new FastReader();
    static PrintWriter out = new PrintWriter(System.out);
    static int N = 1010;
    static int[] primes = new int[N];
    static boolean[] st = new boolean[N];
    static int[] phi = new int[N];
    static int[] s = new int[N];
    static int n, cnt = 0;

    public static void main(String[] args) {
        int T = sc.nextInt();
        ola();
        for (int i = 1; i < N; i++) s[i] = s[i - 1] + phi[i];
        for (int i = 1; i <= T; i++) {
            n = sc.nextInt();
            out.printf("%d %d %d\n", i, n, s[n] * 2 + 1);
        }
        out.flush();
    }


    static void ola() {
        st[0] = st[1] = true;
        phi[1] = 1;
        for (int i = 2; i < N; i++) {
            if (!st[i]) {
                primes[cnt++] = i;
                phi[i] = i - 1;
            }
            for (int j = 0; i * primes[j] < N; j++) {
                st[i * primes[j]] = true;
                if (i % primes[j] == 0) {
                    phi[i * primes[j]] = phi[i] * primes[j];
                    break;
                }
                phi[i * primes[j]] = phi[i] * (primes[j] - 1);
            }
        }
    }
}

class FastReader {
    StringTokenizer st;
    BufferedReader br;

    FastReader() {
        br = new BufferedReader(new InputStreamReader(System.in));
    }

    String next() {
        while (st == null || !st.hasMoreElements()) {
            try {
                st = new StringTokenizer(br.readLine());
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        return st.nextToken();
    }

    int nextInt() {
        return Integer.parseInt(next());
    }

    String nextLine() {
        String s = "";
        try {
            s = br.readLine();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return s;
    }

    long nextLong() {
        return Long.parseLong(next());
    }

    double nextDouble() {
        return Double.parseDouble(next());
    }

    // 是否由下一个
    boolean hasNext() {
        while (st == null || !st.hasMoreTokens()) {
            try {
                String line = br.readLine();
                if (line == null)
                    return false;
                st = new StringTokenizer(line);
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return true;
    }
}
